﻿using Dict.Config;
using System;
using System.Collections.Generic;
using Dict.DataModel;

namespace Battle.Engine.LogicModel
{
    public class BuffOfProperty : Buff {
        
        public override Buff Clone()
        {
            var newBuff = base.Clone() as BuffOfProperty;
            return newBuff;
        }
        public override void Init(TableBuff tableBuff, EngineData engineData)
        {
            base.Init(tableBuff, engineData);
        }

        public override void LoadBuff0()
        {
            
        }

        public override void UnloadBuff0()
        {
            
        }

        public override void Effect()
        {
            switch (factor)
            {
                case TableFactorConst.hp:
                    {
                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.AddHp(this.args1, exportOnceData, HpInfSpecialType.Buff, AttackType.PHY);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.perhp:
                    {//加减当前血量的百分之x
                        this.val = this.buffTargetActor.attribute.hp * this.args1 * CommonMethod.tableAttributeConvert;
                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.AddHp(this.val, exportOnceData, HpInfSpecialType.Buff, AttackType.PHY);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.minusMaxHpPercent:
                    {//爆头：降低最大生命的百分比,不能超过攻击力的args2
                        this.val = this.buffTargetActor.attribute.maxHp * this.args1 * CommonMethod.tableAttributeConvert;
                        AttackType attType = AttackType.NONE;
                        if (this.buffOrigion.GetSourceActor().doUltimateSkill != null)
                        {
                            attType = this.buffOrigion.GetSourceActor().doUltimateSkill.attackType;
                        }
                        else if (this.buffOrigion.GetSourceActor().doSkill != null)
                        {
                            attType = this.buffOrigion.GetSourceActor().doSkill.attackType;
                        }
                        else
                        {
                            attType = this.buffOrigion.GetSourceActor().attackType;
                        }
                        var HeadshotAtt = this.buffOrigion.GetSourceActor().attribute.att.value;
                        if (attType == AttackType.PHY)
                        {
                            HeadshotAtt += this.buffOrigion.GetSourceActor().attribute.patt.value;
                        }
                        else if(attType == AttackType.MAG)
                        {
                            HeadshotAtt += this.buffOrigion.GetSourceActor().attribute.matt.value;
                        }
                        if(this.val > 0)
                        {//加血最多不能超过攻击力的百分之args2
                            if (this.val > (HeadshotAtt * this.args2 * CommonMethod.tableAttributeConvert))
                            {
                                this.val = HeadshotAtt * this.args2 * CommonMethod.tableAttributeConvert;
                            }
                        }
                        else
                        {//减血不能超过攻击力的百分之args2
                            if (this.val < (-1 * HeadshotAtt * this.args2 * CommonMethod.tableAttributeConvert))
                            {
                                this.val = -1 * HeadshotAtt * this.args2 * CommonMethod.tableAttributeConvert;
                            }
                        }
                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.AddHp(this.val, exportOnceData, HpInfSpecialType.Headshot, AttackType.PHY);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.addperReduceHp:
                    {//加减血的百分之x
                        this.val = (this.buffTargetActor.attribute.maxHp - this.buffTargetActor.attribute.hp) * this.args1 * CommonMethod.tableAttributeConvert;
                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.AddHp(this.val, exportOnceData, HpInfSpecialType.Buff, AttackType.PHY);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.att:
                    this.buffTargetActor.attribute.att.AddIncrement(this.args1);
                    break;
                case TableFactorConst.peratt:
                    this.buffTargetActor.attribute.att.AddRate(this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.patt:
                    this.buffTargetActor.attribute.patt.AddIncrement(this.args1);
                    break;
                case TableFactorConst.perpatt:
                    this.buffTargetActor.attribute.patt.AddRate(this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.matt:
                    this.buffTargetActor.attribute.matt.AddIncrement(this.args1);
                    break;
                case TableFactorConst.permatt:
                    this.buffTargetActor.attribute.matt.AddRate(this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.def:
                    this.buffTargetActor.attribute.pdef.AddIncrement(this.args1);
                    this.buffTargetActor.attribute.mdef.AddIncrement(this.args1);
                    break;
                case TableFactorConst.perdef:
                    this.buffTargetActor.attribute.pdef.AddRate(this.args1 * CommonMethod.tableAttributeConvert);
                    this.buffTargetActor.attribute.mdef.AddRate(this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.pdef:
                    this.buffTargetActor.attribute.pdef.AddIncrement(this.args1);
                    break;
                case TableFactorConst.perpdef:
                    this.buffTargetActor.attribute.pdef.AddRate(this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.mdef:
                    this.buffTargetActor.attribute.mdef.AddIncrement(this.args1);
                    break;
                case TableFactorConst.permdef:
                    this.buffTargetActor.attribute.mdef.AddRate(this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.hit:
                    this.buffTargetActor.attribute.hit += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.dodge:
                    this.buffTargetActor.attribute.dodge += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.cri:
                    this.buffTargetActor.attribute.cri += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.criFactor:
                    this.buffTargetActor.attribute.criFactor += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.antiCri:
                    this.buffTargetActor.attribute.antiCri += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.cure:
                    this.buffTargetActor.attribute.cure += this.args1;
                    break;
                case TableFactorConst.heal:
                    this.buffTargetActor.attribute.heal += this.args1;
                    break;
                case TableFactorConst.treatAdd:
                    this.buffTargetActor.attribute.treatAdd += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.damageAdd:
                    this.buffTargetActor.attribute.damageAdd += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.damageReduce:
                    this.buffTargetActor.attribute.damageReduce += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.pdamageReduce:
                    this.buffTargetActor.attribute.pdamageReduce += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.mdamageReduce:
                    this.buffTargetActor.attribute.mdamageReduce += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.angerRate:
                    this.buffTargetActor.attribute.angerRate += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.peranger:
                    this.buffTargetActor.attribute.peranger += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.anger:
                    {
                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.player.AddAnger(this.args1, this.buffTargetActor, exportOnceData);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.angerChange:
                    {//吸取目标args1点怒气
                        double anger = 0;
                        if(this.buffTargetActor.player.angerNum >= this.args1)
                        {
                            anger = this.args1;
                        }
                        else
                        {
                            anger = this.buffTargetActor.player.angerNum;
                        }
                        if(anger > 0)
                        {
                            FExportOnceData exportOnceData = new FExportOnceData();
                            exportOnceData.Init(this);
                            this.buffTargetActor.player.AddAnger(-anger, this.buffTargetActor, exportOnceData);
                            this.buffOrigion.GetSourceActor().player.AddAnger(anger, this.buffOrigion.GetSourceActor(), exportOnceData);
                            this.engineData.exports.Add(exportOnceData);
                        }
                    }
                    break;
                case TableFactorConst.angerChangeAndAddHp:
                    {//吸取目标args1点怒气,并给己方回血
                        double anger = 0;
                        if (this.buffTargetActor.player.angerNum >= this.args1)
                        {
                            anger = this.args1;
                        }
                        else
                        {
                            anger = this.buffTargetActor.player.angerNum;
                        }
                        if (anger > 0)
                        {
                            FExportOnceData exportOnceData = new FExportOnceData();
                            exportOnceData.Init(this);
                            this.buffTargetActor.player.AddAnger(-anger, this.buffTargetActor, exportOnceData);
                            this.buffOrigion.GetSourceActor().player.AddAnger(anger, this.buffOrigion.GetSourceActor(), exportOnceData);

                            //获取目标
                            List<SelectLimitCondition> limitConditions = this.engineData.LimitConditions(false, true, true); ;
                            List<FActor> targets = this.engineData.SelectTargetActors(false, (int)this.args2, this.buffOrigion.GetSourceActor(), null, limitConditions);
                            foreach (var target in targets)
                            {
                                FActor sactor = this.buffOrigion.GetSourceActor();
                                double att = sactor.attribute.att.value;
                                double attAdd = sactor.attribute.patt.value;
                                double cure = sactor.attribute.cure;
                                double heal = target.attribute.heal;
                                double total_treat = (att + attAdd) * this.args3 * anger * CommonMethod.tableAttributeConvert * (1 + sactor.attribute.treatAdd) + cure + heal;
                                
                                target.AddHp(total_treat, exportOnceData, HpInfSpecialType.Recover, AttackType.TREAT);
                            }
                            this.engineData.exports.Add(exportOnceData);
                        }
                    }
                    break;
                case TableFactorConst.angerAndhp:
                    {
                        double anger = 0;
                        if (this.args1 > 0)
                            anger = this.args1;
                        else
                            anger = (0 - this.args1);
                        if (this.buffTargetActor.player.angerNum < anger)
                        {
                            anger = this.buffTargetActor.player.angerNum;
                        }
                        if (anger > 0)
                        {
                            FExportOnceData exportOnceData = new FExportOnceData();
                            exportOnceData.Init(this);
                            if (this.args1 > 0)
                                this.buffTargetActor.player.AddAnger(anger, this.buffTargetActor, exportOnceData);
                            else
                                this.buffTargetActor.player.AddAnger(-anger, this.buffTargetActor, exportOnceData);
                            this.val = this.buffTargetActor.attribute.maxHp * this.args2 * CommonMethod.tableAttributeConvert;
                            if (this.args3 != 0 && this.buffOrigion != null)
                            {
								if(this.val > 0) 
								{
									if (this.val > (this.buffOrigion.GetSourceActor().attribute.att.value * this.args3 * CommonMethod.tableAttributeConvert))
										this.val = this.buffOrigion.GetSourceActor().attribute.att.value * this.args3 * CommonMethod.tableAttributeConvert;
								} 
								else 
								{
									if (this.val < (this.buffOrigion.GetSourceActor().attribute.att.value * this.args3 * CommonMethod.tableAttributeConvert))
										this.val = this.buffOrigion.GetSourceActor().attribute.att.value * this.args3 * CommonMethod.tableAttributeConvert;
								}
                            }
                            this.val = this.val * anger;
                            this.buffTargetActor.AddHp(this.val, exportOnceData, HpInfSpecialType.Buff, AttackType.PHY);
                            this.engineData.exports.Add(exportOnceData);
                        }
                    }
                    break;
                case TableFactorConst.blockDam:
                    this.buffTargetActor.attribute.block += (this.args1 * CommonMethod.tableAttributeConvert);
                    this.buffTargetActor.attribute.blockDam = (this.args2 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.poison:
                    this.buffTargetActor.attribute.poison += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.antiPoison:
                    this.buffTargetActor.attribute.antiPoison += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.fire:
                    this.buffTargetActor.attribute.fire -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.antiFire:
                    this.buffTargetActor.attribute.antiFire -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.counterStrikeDam:
                    this.buffTargetActor.attribute.counterStrikeDam += (this.args1 * CommonMethod.tableAttributeConvert);
                    this.buffTargetActor.attribute.counterStrikeReal = false;
                    this.buffTargetActor.attribute.counterStrikeSelect = (int)this.args2;
                    break;
                case TableFactorConst.counterStrikeRealDam:
                    this.buffTargetActor.attribute.counterStrikeDam += (this.args1 * CommonMethod.tableAttributeConvert);
                    this.buffTargetActor.attribute.counterStrikeReal = true;
                    this.buffTargetActor.attribute.counterStrikeSelect = (int)this.args2;
                    break;
                case TableFactorConst.additionAttDam:
                case TableFactorConst.additionAttRealDam:
                    {//额外攻击 减血=(攻击+物法攻击-目标物法防御)*额外攻击系数*(1+伤害加成-目标伤害减免-目标物法伤害减免)
                        FActor sactor = this.buffOrigion.GetSourceActor();
                        double att = sactor.attribute.att.value;
                        double attAdd = sactor.attackType == AttackType.PHY ? sactor.attribute.patt.value : sactor.attribute.matt.value;
                        double def = sactor.attackType == AttackType.PHY ? this.buffTargetActor.attribute.pdef.value : this.buffTargetActor.attribute.mdef.value;
                        double damageAdd = sactor.attribute.damageAdd;
                        double damageReduce = this.buffTargetActor.attribute.damageReduce;
                        double damageReduceAdd = sactor.attackType == AttackType.PHY ? this.buffTargetActor.attribute.pdamageReduce : this.buffTargetActor.attribute.mdamageReduce;
                        if (factor.Equals(TableFactorConst.additionAttRealDam))
                        {//无视对方防御及免伤
                            def = 0;
                            damageReduce = 0;
                            damageReduceAdd = 0;
                        }
                        double damage = (1 + damageAdd - damageReduce - damageReduceAdd) < 0 ? 0 : (1 + damageAdd - damageReduce - damageReduceAdd);
                        double totalDamage = (att + attAdd - def) * this.args1 * CommonMethod.tableAttributeConvert * damage;
                        if(totalDamage < 1)
                        {
                            totalDamage = 1;
                        }
                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.AddHp(-totalDamage, exportOnceData, HpInfSpecialType.AdditionAtt, sactor.attackType);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.minusDebuffOdds:
                    this.buffTargetActor.attribute.minusDebuffOdds += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.minusDebuffperOdds:
                    this.buffTargetActor.attribute.minusDebuffperOdds += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.minusAddperhp:
                    this.buffTargetActor.attribute.minusAddperhp += (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.recover:
                    {
                        FActor sactor = this.buffOrigion.GetSourceActor();
                        double att = sactor.attribute.att.value;
                        double attAdd = sactor.attribute.patt.value;
                        double cure = sactor.attribute.cure;
                        double heal = this.buffTargetActor.attribute.heal;
                        double total_treat = (att + attAdd) * this.args1 * CommonMethod.tableAttributeConvert * (1 + sactor.attribute.treatAdd) + cure + heal;

                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.AddHp(total_treat, exportOnceData, HpInfSpecialType.Recover, AttackType.TREAT);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.recoverBySelfRound:
                    {
                        FActor sactor = this.buffOrigion.GetSourceActor();
                        double att = sactor.attribute.att.value;
                        double attAdd = sactor.attribute.patt.value;
                        double cure = sactor.attribute.cure;
                        double heal = this.buffTargetActor.attribute.heal;
                        this.val = (att + attAdd) * this.args1 * CommonMethod.tableAttributeConvert * (1 + sactor.attribute.treatAdd) + cure + heal;
                    }
                    break;
                case TableFactorConst.bleeding:
                    this.buffTargetActor.attribute.bleeding += this.args1 * CommonMethod.tableAttributeConvert;
                    break;
                case TableFactorConst.lifestealHp:
                    this.buffTargetActor.attribute.lifestealHp += (this.args1 * CommonMethod.tableAttributeConvert);
                    this.buffTargetActor.attribute.lifestealSelect = (int)this.args2;
                    break;
                case TableFactorConst.shield:
                    this.buffTargetActor.attribute.shield += this.args1;
                    this.type = TableFactorConst.shield;
                    this.val = this.args1;
                    break;
                case TableFactorConst.pshield:
                    this.buffTargetActor.attribute.pshield += this.args1;
                    this.type = TableFactorConst.pshield;
                    this.val = this.args1;
                    break;
                case TableFactorConst.mshield:
                    this.buffTargetActor.attribute.mshield += this.args1;
                    this.type = TableFactorConst.mshield;
                    this.val = this.args1;
                    break;
                case TableFactorConst.reboundPerMaxhp:
                    {
                        this.buffTargetActor.state = FActorState.IDLE;
                        this.buffTargetActor.ResetRound(this.engineData);
                        //foreach (var skill in this.buffTargetActor.skills)
                        //{
                        //    skill.cooldownCur = 0;
                        //}
                        if (this.buffOrigion != null)
                        {
                            this.buffOrigion.GetSourceActor().isReboundBuff = true;
                        }
                        this.buffTargetActor.isRebound = true;
                        this.buffTargetActor.buffManager.ClearAllBuff();
                        this.val = this.buffTargetActor.attribute.maxHp * this.args1 * CommonMethod.tableAttributeConvert;
                        Debug.LogFightMsg100("--------rebound: round=" + this.engineData.roundNum + ", rebound:" + this.buffTargetActor.heroId + ", camp:" + this.buffTargetActor.player.camp + ", position:" + this.buffTargetActor.MainPosition.ToFPID());

                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.AddHp(this.val, exportOnceData, HpInfSpecialType.Rebound, AttackType.PHY);
                        this.buffTargetActor.player.deadActors.Remove(buffTargetActor);
                        
                        TalentBuffOrigin tal = (TalentBuffOrigin)this.buffOrigion;
                        string[] buffIds = param.Split(',');
                        foreach (var buffId in buffIds)
                        {
                            Buff b = FBuffFactory.CreateBuff(buffId, this.engineData);
                            b.Clone().LoadBuff(this.buffTargetActor, tal.sourceTalent, timer, exportOnceData);
                        }
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.reliveAndinvisible:
                    {
                        this.buffTargetActor.state = FActorState.IDLE;
                        this.buffTargetActor.ResetRound(this.engineData);
                        //foreach (var skill in this.buffTargetActor.skills)
                        //{
                        //    skill.cooldownCur = 0;
                        //}
                        this.buffTargetActor.isRelive = true;
                        this.val = this.buffTargetActor.attribute.maxHp * this.args1 * CommonMethod.tableAttributeConvert;
                        this.buffTargetActor.stateManager.AddStateNumByType(this, TableFactorConst.invisible, 1);
                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.AddHp(this.val, exportOnceData, HpInfSpecialType.Rebound, AttackType.PHY);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.minusSkillCoolDown:
                    int index = 0;
                    if (this.buffTargetActor.doUltimateSkill != null)
                    {//大招
                        index = this.buffTargetActor.doUltimateSkill.index;
                    }
                    else if (this.buffTargetActor.doSkill != null)
                    {//小招
                        index = this.buffTargetActor.doSkill.index;
                    }
                    foreach (var skill in this.buffTargetActor.skills)
                    {
                        if(skill.index == index)
                        {
                            skill.cooldownCur-= (int)this.args1;
                        }
                    }
                    break;
                case TableFactorConst.treatHurtAndAddperAtt:
                    {
                        double addhp = (buffTargetActor.attribute.maxHp - buffTargetActor.attribute.hp) * this.args1 * CommonMethod.tableAttributeConvert;
                        this.val = addhp * this.args2 * CommonMethod.tableAttributeConvert;
                        this.buffTargetActor.attribute.att.AddIncrement(this.val);
                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.AddHp(addhp, exportOnceData, HpInfSpecialType.Buff, AttackType.PHY);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.damShareByMaxHpTeammate:
                    this.buffTargetActor.attribute.damShareFactor = this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.damShareActors.Clear();
                    foreach(var actor in this.buffTargetActor.player.actors)
                    {
                        if(actor.attribute.hp <= 0 || actor.uniqueId.Equals(this.buffTargetActor.uniqueId))
                        {
                            continue;
                        }
                        else
                        {
                            if(this.buffTargetActor.attribute.damShareActors.Count == 0)
                            {
                                this.buffTargetActor.attribute.damShareActors.Add(actor);
                            }
                            else if (actor.attribute.hp == this.buffTargetActor.attribute.damShareActors[0].attribute.hp)
                            {
                                this.buffTargetActor.attribute.damShareActors.Add(actor);
                            }
                            else if(actor.attribute.hp > this.buffTargetActor.attribute.damShareActors[0].attribute.hp)
                            {
                                this.buffTargetActor.attribute.damShareActors.Clear();
                                this.buffTargetActor.attribute.damShareActors.Add(actor);
                            }
                        }
                    }
                    break;
                case TableFactorConst.sameDamForRandom:
                    this.buffTargetActor.attribute.sameDamForRandom += this.args1 * CommonMethod.tableAttributeConvert;
                    break;
                case TableFactorConst.additionAttBySelfRound:
                    //实际生效的时候再做处理
                    break;
                case TableFactorConst.permaxHpBySelfRound:
                    {//在回合开始时 加或者减 最大血量的百分比 ,不能超过攻击力的args2
                        this.val = this.buffTargetActor.attribute.maxHp * this.args1 * CommonMethod.tableAttributeConvert;
                        AttackType attType = AttackType.NONE;
                        if(this.args2 > 0)
                        {
                            if (this.buffOrigion.GetSourceActor().doUltimateSkill != null)
                            {
                                attType = this.buffOrigion.GetSourceActor().doUltimateSkill.attackType;
                            }
                            else if (this.buffOrigion.GetSourceActor().doSkill != null)
                            {
                                attType = this.buffOrigion.GetSourceActor().doSkill.attackType;
                            }
                            else
                            {
                                attType = this.buffOrigion.GetSourceActor().attackType;
                            }
                            var HeadshotAtt = this.buffOrigion.GetSourceActor().attribute.att.value;
                            if (attType == AttackType.PHY)
                            {
                                HeadshotAtt += this.buffOrigion.GetSourceActor().attribute.patt.value;
                            }
                            else if (attType == AttackType.MAG)
                            {
                                HeadshotAtt += this.buffOrigion.GetSourceActor().attribute.matt.value;
                            }
                            if (this.val > 0)
                            {//加血最多不能超过攻击力的百分之args2
                                if (this.val > (HeadshotAtt * this.args2 * CommonMethod.tableAttributeConvert))
                                {
                                    this.val = HeadshotAtt * this.args2 * CommonMethod.tableAttributeConvert;
                                }
                            }
                            else
                            {//减血不能超过攻击力的百分之args2
                                if (this.val < (-1 * HeadshotAtt * this.args2 * CommonMethod.tableAttributeConvert))
                                {
                                    this.val = -1 * HeadshotAtt * this.args2 * CommonMethod.tableAttributeConvert;
                                }
                            }
                        }
                    }
                    break;
                case TableFactorConst.permaxHp:
                    {//加最大血量的百分比
                        this.val = this.buffTargetActor.attribute.maxHp * this.args1 * CommonMethod.tableAttributeConvert;
                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.AddHp(this.val, exportOnceData, HpInfSpecialType.Buff, AttackType.PHY);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.additionSourcepermaxHp:
                    {//额外攻击 减血=来源者的最大血量的x%
                        FActor sactor = this.buffOrigion.GetSourceActor();
                        double totalDamage = sactor.attribute.maxHp * this.args1 * CommonMethod.tableAttributeConvert;
                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.AddHp(-totalDamage, exportOnceData, HpInfSpecialType.AdditionAtt, sactor.attackType);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.addAngerByXAliveNum:
                    {
                        FExportOnceData exportOnceData = new FExportOnceData();
                        exportOnceData.Init(this);
                        this.buffTargetActor.player.AddAnger(this.args1*this.buffTargetActor.GetValueByType(TableFactorConst.aliveNum), this.buffTargetActor, exportOnceData);
                        this.engineData.exports.Add(exportOnceData);
                    }
                    break;
                case TableFactorConst.maxhpLimitDam:
                    this.buffTargetActor.attribute.maxhpLimitDam = this.args1 * CommonMethod.tableAttributeConvert * this.buffTargetActor.attribute.maxHp;
                    break;
                case TableFactorConst.minEnemyMoreDam:
                    if(this.engineData.GetNumActor(this.buffTargetActor.player.enemyCamp) == 1)
                    {
                        this.val = this.args1 * CommonMethod.tableAttributeConvert;
                    }
                    else if(this.engineData.GetNumActor(this.buffTargetActor.player.enemyCamp) == 2)
                    {
                        this.val = this.args2 * CommonMethod.tableAttributeConvert;
                    }
                    else if (this.engineData.GetNumActor(this.buffTargetActor.player.enemyCamp) == 3)
                    {
                        this.val = this.args3 * CommonMethod.tableAttributeConvert;
                    }
                    this.buffTargetActor.attribute.damageAdd += this.val;
                    break;
                default:
                    break;
            }
        }

        public override void UnEffect()
        {
            switch (factor)
            {
                case TableFactorConst.hp:
                case TableFactorConst.perhp:
                case TableFactorConst.minusMaxHpPercent:
                case TableFactorConst.addperReduceHp:
                    //血量相关值无法回退，不做处理
                    break;
                case TableFactorConst.att:
                    this.buffTargetActor.attribute.att.AddIncrement(-this.args1);
                    break;
                case TableFactorConst.peratt:
                    this.buffTargetActor.attribute.att.AddRate(-this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.patt:
                    this.buffTargetActor.attribute.patt.AddIncrement(-this.args1);
                    break;
                case TableFactorConst.perpatt:
                    this.buffTargetActor.attribute.patt.AddRate(-this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.matt:
                    this.buffTargetActor.attribute.matt.AddIncrement(-this.args1);
                    break;
                case TableFactorConst.permatt:
                    this.buffTargetActor.attribute.matt.AddRate(-this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.def:
                    this.buffTargetActor.attribute.pdef.AddIncrement(-this.args1);
                    this.buffTargetActor.attribute.mdef.AddIncrement(-this.args1);
                    break;
                case TableFactorConst.perdef:
                    this.buffTargetActor.attribute.pdef.AddRate(-this.args1 * CommonMethod.tableAttributeConvert);
                    this.buffTargetActor.attribute.mdef.AddRate(-this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.pdef:
                    this.buffTargetActor.attribute.pdef.AddIncrement(-this.args1);
                    break;
                case TableFactorConst.perpdef:
                    this.buffTargetActor.attribute.pdef.AddRate(-this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.mdef:
                    this.buffTargetActor.attribute.mdef.AddIncrement(-this.args1);
                    break;
                case TableFactorConst.permdef:
                    this.buffTargetActor.attribute.mdef.AddRate(-this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.hit:
                    this.buffTargetActor.attribute.hit -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.dodge:
                    this.buffTargetActor.attribute.dodge -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.cri:
                    this.buffTargetActor.attribute.cri -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.criFactor:
                    this.buffTargetActor.attribute.criFactor -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.antiCri:
                    this.buffTargetActor.attribute.antiCri -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.cure:
                    this.buffTargetActor.attribute.cure -= this.args1;
                    break;
                case TableFactorConst.heal:
                    this.buffTargetActor.attribute.heal -= this.args1;
                    break;
                case TableFactorConst.treatAdd:
                    this.buffTargetActor.attribute.treatAdd -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.damageAdd:
                    this.buffTargetActor.attribute.damageAdd -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.damageReduce:
                    this.buffTargetActor.attribute.damageReduce -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.pdamageReduce:
                    this.buffTargetActor.attribute.pdamageReduce -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.mdamageReduce:
                    this.buffTargetActor.attribute.mdamageReduce -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.angerRate:
                    this.buffTargetActor.attribute.angerRate -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.peranger:
                    this.buffTargetActor.attribute.peranger -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.anger:
                case TableFactorConst.angerChange:
                case TableFactorConst.angerChangeAndAddHp:
                case TableFactorConst.angerAndhp:
                    //怒气无法回退，不做处理
                    break;
                case TableFactorConst.blockDam:
                    this.buffTargetActor.attribute.block -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.poison:
                    this.buffTargetActor.attribute.poison -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.antiPoison:
                    this.buffTargetActor.attribute.antiPoison -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.fire:
                    this.buffTargetActor.attribute.fire -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.antiFire:
                    this.buffTargetActor.attribute.antiFire -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.counterStrikeDam:
                case TableFactorConst.counterStrikeRealDam:
                    this.buffTargetActor.attribute.counterStrikeDam -= (this.args1 * CommonMethod.tableAttributeConvert);
                    this.buffTargetActor.attribute.counterStrikeReal = false;
                    break;
                case TableFactorConst.additionAttDam:
                case TableFactorConst.additionAttRealDam:
                    break;
                case TableFactorConst.minusDebuffOdds:
                    this.buffTargetActor.attribute.minusDebuffOdds -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.minusDebuffperOdds:
                    this.buffTargetActor.attribute.minusDebuffperOdds -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.minusAddperhp:
                    this.buffTargetActor.attribute.minusAddperhp -= (this.args1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.recover:
                    break;
                case TableFactorConst.recoverBySelfRound:
                    break;
                case TableFactorConst.bleeding:
                    this.buffTargetActor.attribute.bleeding -= this.args1 * CommonMethod.tableAttributeConvert;
                    break;
                case TableFactorConst.lifestealHp:
                    this.buffTargetActor.attribute.lifestealHp -= (this.args1 * CommonMethod.tableAttributeConvert);
                    this.buffTargetActor.attribute.lifestealSelect = 0;
                    break;
                case TableFactorConst.shield:
                    this.buffTargetActor.attribute.shield = 0;
                    break;
                case TableFactorConst.pshield:
                    this.buffTargetActor.attribute.pshield = 0;
                    break;
                case TableFactorConst.mshield:
                    this.buffTargetActor.attribute.mshield = 0;
                    break;
                case TableFactorConst.reboundPerMaxhp:
                    //复活不用做处理
                    break;
                case TableFactorConst.reliveAndinvisible:
                    this.buffTargetActor.stateManager.AddStateNumByType(this, TableFactorConst.invisible, -1);
                    break;
                case TableFactorConst.minusSkillCoolDown:
                    break;
                case TableFactorConst.treatHurtAndAddperAtt:
                    this.buffTargetActor.attribute.att.AddIncrement(-this.val);
                    break;
                case TableFactorConst.damShareByMaxHpTeammate:
                    this.buffTargetActor.attribute.damShareFactor = 0;
                    this.buffTargetActor.attribute.damShareActors.Clear();
                    break;
                case TableFactorConst.sameDamForRandom:
                    this.buffTargetActor.attribute.sameDamForRandom -= this.args1 * CommonMethod.tableAttributeConvert;
                    break;
                case TableFactorConst.additionAttBySelfRound:
                    break;
                case TableFactorConst.permaxHpBySelfRound:
                    break;
                case TableFactorConst.permaxHp:
                    break;
                case TableFactorConst.additionSourcepermaxHp:
                    break;
                case TableFactorConst.addAngerByXAliveNum:
                    break;
                case TableFactorConst.maxhpLimitDam:
                    this.buffTargetActor.attribute.maxhpLimitDam = 0;
                    break;
                case TableFactorConst.minEnemyMoreDam:
                    this.buffTargetActor.attribute.damageAdd -= this.val;
                    break;
                default:
                    break;
            }
        }
        
    }
}
